package com.eonmind.knowledge.controller;

import com.eonmind.common.contract.data.response.PageResponse;
import com.eonmind.common.contract.data.response.ResponseEntity;
import com.eonmind.common.security.annotations.UserInfo;
import com.eonmind.knowledge.dto.KnowledgeDto;
import com.eonmind.knowledge.service.KnowledgeService;
import com.eonmind.user.contract.dto.UserInfoData;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 知识库操作接口
 */
@RestController
@RequestMapping("/knowledge")
public class KnowledgeController {

    @Resource
    private KnowledgeService knowledgeService;


    /**
     * 创建知识库
     *
     * @param knowledgeCreateRequest
     * @return ResponseEntity<String>
     * @ignoreParams userInfoData
     */
    @UserInfo
    @PostMapping("/create")
    public ResponseEntity<String> createKnowledge(@RequestBody KnowledgeDto.KnowledgeCreateRequest knowledgeCreateRequest, UserInfoData userInfoData) {
        knowledgeService.saveKnowledge(knowledgeCreateRequest, userInfoData);
        return ResponseEntity.success();
    }

    /**
     * 更新知识库
     *
     * @param knowledgeUpdateRequest
     * @return ResponseEntity<String>
     * @ignoreParams userInfoData
     */
    @UserInfo
    @PostMapping("/update")
    public ResponseEntity<String> updateKnowledge(@RequestBody KnowledgeDto.KnowledgeUpdateRequest knowledgeUpdateRequest, UserInfoData userInfoData) {
        knowledgeService.updateKnowledge(knowledgeUpdateRequest, userInfoData);
        return ResponseEntity.success();
    }

    /**
     * 删除知识库
     *
     * @param knowledgeDeleteRequest
     * @return ResponseEntity<String>
     * @ignoreParams userInfoData
     */
    @UserInfo
    @PostMapping("/delete")
    public ResponseEntity<String> deleteKnowledge(@RequestBody KnowledgeDto.KnowledgeDeleteRequest knowledgeDeleteRequest, UserInfoData userInfoData) {
        knowledgeService.deleteKnowledge(knowledgeDeleteRequest, userInfoData);
        return ResponseEntity.success();
    }

    /**
     * 获取用户所有知识库
     *
     * @param userInfoData
     * @return ResponseEntity<List < KnowledgeDto.KnowledgeResponse>>
     * @ignoreParams userInfoData
     */
    @UserInfo
    @PostMapping("/listKnowledge")
    public ResponseEntity<PageResponse<KnowledgeDto.KnowledgeResponse>> listKnowledge(UserInfoData userInfoData, @RequestBody KnowledgeDto.KnowledgePageRequest knowledgePageRequest) {
        PageResponse<KnowledgeDto.KnowledgeResponse> knowledgeResponsePageResponse = knowledgeService.listKnowledge(userInfoData, knowledgePageRequest);
        return ResponseEntity.success(knowledgeResponsePageResponse);
    }

}
